using Uantek.Device.Communication.Models;

namespace Uantek.Device.Communication.Services.Interfaces
{
    /// <summary>
    /// 设备通信服务接口
    /// </summary>
    public interface IDeviceCommunicationService
    {
        /// <summary>
        /// 添加设备连接
        /// </summary>
        /// <param name="deviceId">设备ID</param>
        /// <param name="protocolName">协议名称</param>
        /// <param name="transportType">传输类型</param>
        /// <param name="connectionParameters">连接参数</param>
        /// <returns>操作结果</returns>
        Task<CommunicationResult> AddDeviceAsync(string deviceId, string protocolName, string transportType, Dictionary<string, object> connectionParameters);

        /// <summary>
        /// 移除设备连接
        /// </summary>
        /// <param name="deviceId">设备ID</param>
        /// <returns>操作结果</returns>
        Task<CommunicationResult> RemoveDeviceAsync(string deviceId);

        /// <summary>
        /// 连接设备
        /// </summary>
        /// <param name="deviceId">设备ID</param>
        /// <returns>连接结果</returns>
        Task<CommunicationResult> ConnectDeviceAsync(string deviceId);

        /// <summary>
        /// 断开设备连接
        /// </summary>
        /// <param name="deviceId">设备ID</param>
        /// <returns>断开结果</returns>
        Task<CommunicationResult> DisconnectDeviceAsync(string deviceId);

        /// <summary>
        /// 向设备发送命令
        /// </summary>
        /// <param name="deviceId">设备ID</param>
        /// <param name="command">命令</param>
        /// <param name="parameters">参数</param>
        /// <returns>命令执行结果</returns>
        Task<CommunicationResult<string>> SendCommandAsync(string deviceId, string command, Dictionary<string, object>? parameters = null);

        /// <summary>
        /// 获取设备状态
        /// </summary>
        /// <param name="deviceId">设备ID</param>
        /// <returns>设备状态</returns>
        Task<DeviceStatus?> GetDeviceStatusAsync(string deviceId);

        /// <summary>
        /// 获取所有设备状态
        /// </summary>
        /// <returns>所有设备状态列表</returns>
        Task<IEnumerable<DeviceStatus>> GetAllDeviceStatusAsync();

        /// <summary>
        /// 启动设备通信服务
        /// </summary>
        /// <returns>启动结果</returns>
        Task<CommunicationResult> StartAsync();

        /// <summary>
        /// 停止设备通信服务
        /// </summary>
        /// <returns>停止结果</returns>
        Task<CommunicationResult> StopAsync();

        /// <summary>
        /// 设备数据接收事件
        /// </summary>
        event EventHandler<DeviceDataModel>? DeviceDataReceived;

        /// <summary>
        /// 设备状态变化事件
        /// </summary>
        event EventHandler<DeviceStatus>? DeviceStatusChanged;
    }
}